import java.util.Scanner;

//查找两个字符串a,b中的最长公共子串
public class test {
    import java.util.*;

    public class Main{
        public static void main(String[]args){
            Scanner sc=new Scanner(System.in);
            while(sc.hasNext()){
                String str1=sc.nextLine();
                String str2=sc.nextLine();
                if(str1.length()<str2.length()){
                    System.out.println(getMaxSubstr(str1,str2));
                }else{
                    System.out.println(getMaxSubstr(str2,str1));
                }
            }
        }
        //假设str1长度短
        public static String getMaxSubstr(String str1,String str2){
            char[]arr1=str1.toCharArray();
            char[]arr2=str2.toCharArray();
            int len1=arr1.length;
            int len2=arr2.length;
            //最长子串的起始位置
            int start=0;
            //最长的子串长度
            int maxLen=0;
            //多增加一行一列，作为辅助状态
            int[][] maxSubLen=new int[len1+1][len2+1];
            //以str1的第i个字符结尾和以str2的第j个字符结尾的最长公共字串的长度
            for(int i=1;i<=len1;i++){
                for(int j=1;j<=len2;j++){
                    //如果第i个字符和第j个字符相等，则进行累加
                    if(arr1[i-1]==arr2[j-1]){
                        maxSubLen[i][j]=maxSubLen[i-1][j-1]+1;
                        //更新
                        if(maxLen<maxSubLen[i][j]){
                            maxLen=maxSubLen[i][j];
                            start=i-maxLen;
                        }
                    }
                }
            }
            return str1.substring(start,start+maxLen);
        }
    }
}
